home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / maestro / source / quotemkr / font.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-15  |  14.2 KB  |  424 lines

  1. /*
  2.  * Copyright (c) 1990, 1991, 1992 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and 
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that (i) the above copyright notices and this permission notice appear in
  7.  * all copies of the software and related documentation, and (ii) the name
  8.  * Stanford may not be used in any advertising or publicity relating to
  9.  * the software without the specific, prior written permission of
  10.  * Stanford.
  11.  * 
  12.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  13.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  14.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  15.  *
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  17.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
  18.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT
  19.  * ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY,
  20.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21.  * SOFTWARE.
  22.  */
  23.  
  24. /*$Header: /Source/Media/collab/QuoteMaker/RCS/font.c,v 2.13 92/09/25 14:31:26 drapeau Exp $*/
  25. /* $Log:    font.c,v $
  26.  * Revision 2.13  92/09/25  14:31:26  drapeau
  27.  * Fixed errors in the way the quoted text window was being located.  The
  28.  * earlier version used the XView attributes "XV_WIDTH", "XV_HEIGHT", "XV_X",
  29.  * and "XV_Y".  This version now uses the more proper "frame_get_rect()" and
  30.  * "frame_set_rect()" functions for window placement and sizing.
  31.  * Also, some cosmetic changes were made to enhance readability and ANSI
  32.  * compliance.
  33.  * 
  34.  * Revision 2.12  92/05/29  12:41:23  drapeau
  35.  * Modified code to track new name of the MAEstro "Selection" structure;
  36.  * it is now named "MAESelection".
  37.  * 
  38.  * Revision 2.11  92/05/14  15:43:31  drapeau
  39.  * * Updated copyright information.
  40.  * 
  41.  * Revision 2.10  91/12/31  18:41:45  drapeau
  42.  * Removed the inclusion of string.h, since XView will include the
  43.  * appropriate definitions.
  44.  * 
  45.  * Revision 2.0  91/09/30  15:02:28  derek
  46.  * Version number changed to 2.0.
  47.  * 
  48.  * Revision 1.6  91/09/15  20:34:05  derek
  49.  * The function ShowPreviewFunctionsPanel() is removed.  Also, in 
  50.  * PreloadFontOntoQTW(), a statement is added to clear the quote window
  51.  * before loading fonts.
  52.  * 
  53.  * Revision 1.5  91/09/05  15:47:59  derek
  54.  * The following changes are made:
  55.  * 1.      The name "Quoted Text Window" has been changed to "Quote Window"
  56.  *         in the app.
  57.  * 2.      ShowApplication() and HideApplication() is changed because of the
  58.  *         the change of quote window from a popup to a basewindow.
  59.  * 3.      The QuitProc of QuoteMaker is fixed so that the quote window,
  60.  *         as a base window, will be destroyed separately.
  61.  * 4.      Now hitting return in the label field will not result in adding
  62.  *         a new edit.
  63.  * 5.      Copyright messages are included in front of every .h and .c file.
  64.  * 6.      The scrollbar and the footer of the Quote Window are hidden.
  65.  * 7.      I have changed the include openpanel.h statement in QuoteMaker.c
  66.  *         to include Browse.h.
  67.  * 8.      The delete bug corresponding to the change that the panel-list
  68.  *         must have a choice -- is fixed.  Also, the corresponding bug
  69.  *         for deleteAll is also fixed.
  70.  * 9.      Now, deleteAll and deletion of the last item in Panel_list
  71.  *         will cause the panel-list to be destroyed and a new one will
  72.  *         be created.
  73.  * 10.     GetOpt files have been removed from the directory.  Corresponding
  74.  *         changes are made.
  75.  * 11.     The start and end byte fields are removed from the main panel.
  76.  * 12.     I have put iconify, hide and show quote window to be buttons
  77.  *         instead of menu options.
  78.  * 13.     I have removed the PreviewPanelPopup and incorporated its features into
  79.  *         the main panel.  The three buttons:  pause, play and stop and
  80.  *         the DurationGauge are moved to the main panel.  But the
  81.  *         StatusMessage is removed.
  82.  * 14.     The EnableLocationChange and EnableSizeChange choice setting
  83.  *         are removed.  There are no longer such choices.
  84.  * 15.     Right now if a panel-item is selected and if another panel-item
  85.  *         is picked, the DeselectList() operation in the middle is
  86.  *         eliminated.  This operation involves updating of text fields and
  87.  *         messages and its removal speeds up the program.  The panel-list
  88.  *         must now take at least one choice.  (A choice must be selected
  89.  *         whenever there is at least one item on the list).  And now
  90.  *         there is no way to deselect a list by the user.
  91.  * 16.     The "modified bit" associated with the CurrentSelectionNumberLabel
  92.  *         is implemented.  Now, if a selection is picked, and if either
  93.  *         the quote window is moved or any text fields are changed, the
  94.  *         modified bit will be on.
  95.  * 17.     The Show-text-window button and the Show-quote-window-specifications-popup
  96.  *         button are removed.  They are now menu options under the Options Menu.
  97.  * 18.     The Modify button has its name changed to "Update Edit".
  98.  * 
  99.  * Revision 1.4  91/08/27  14:37:31  derek
  100.  * The following things are done:
  101.  * 1.    The QuotedTextWindow is changed from a base window to a popup window
  102.  *     (now it's called QuotedMaker_quotedTextBaseWindow).  I have also
  103.  *     added a few options: show, hide and iconify QTW and also created
  104.  *     an icon for QTW.
  105.  * 2.    The quoted text will be set in PerformSelection() instead of 
  106.  *     in SetSelection().
  107.  * 3.    I have changed the Document field and the EditList field of 
  108.  *     QuoteMaker so that they will display fill paths.
  109.  * 
  110.  * Revision 1.3  91/08/26  12:10:13  derek
  111.  * The following things are done:
  112.  * 1.    I have added a few notice_prompts to the linkProtocol (network)
  113.  *     functions to give warnings about invalid document names.
  114.  * 2.    The quoted text window will by default be hidden during "blank"
  115.  *     times. ie. when it is not displaying any text.  The interface has
  116.  *     been changed so that it now has a HideQuotedTExtWindowAfterPreview
  117.  *     check box.  The QuotedTextWindow will either stay on the screen
  118.  *     or be hidden as the author desires.
  119.  * 3.    Make the changes corresponding to the changing of name from OpenPanel
  120.  *     to Browse.
  121.  * 4.    The return value bug for OpenHandler, SaveHandler is fixed.
  122.  * 5.    I have changed the code so that Save and SaveAs will behave correctly.
  123.  *     The SaveAs PopUp/Open PopUp are removed.  Browse check is 
  124.  *     incorporated in the applications.
  125.  * 6.    The QuoteMaker file format has been changed.  An EditNumber field    
  126.  *     has been added.
  127.  * 7.    Changes corresponding to the return value by OpenDoc and SetSelection
  128.  *     are made.
  129.  * 8.    GetAppIcon() has been implemented.
  130.  * 9.    Fonts specified in the Edit-list will be preloaded in OpenDoc().
  131.  *     This will hopefully eliminate the startup delay needed to load
  132.  *     the font when we put text onto the Quoted TExt Window for the 
  133.  *     first time.
  134.  * 10.    The "play" button will now play things specified in the 
  135.  *     QuotedTExtWindowSpecificationsPopUp (instead of those specified
  136.  *     in the editList).
  137.  * 11.    The show selection button is replaced by the set selection button.
  138.  *     The Set Selection button willl now not only set the current
  139.  *     edit parameters but will also highlight the corresponding section
  140.  *     in the text.  Also, when one item on the panel-list is clicked on,
  141.  *     the corresponding segment in the text will also be highlighted.
  142.  * 12.    Notify events which tells the app to show the size and location 
  143.  *     of the Quoted Text Window are set up.  ie. those text-fields
  144.  *     on the interface will be updated instantaneously.
  145.  * 16.    editList.label is being sent across the network.
  146.  * 17.    The title bar and the footer of the QuotedTExtWindow are hidden.
  147.  * 
  148.  * Revision 1.2  91/07/22  16:46:54  derek
  149.  * I have added 4 buttons to get and set the current
  150.  * location and size of the quoted text window.
  151.  * 
  152.  * Revision 1.1  91/07/15  12:19:00  derek
  153.  * Initial revision
  154.  *  */
  155. static char rcsid[] = "$Header: /Source/Media/collab/QuoteMaker/RCS/font.c,v 2.13 92/09/25 14:31:26 drapeau Exp $";
  156.  
  157. #include <stdio.h>
  158. #include <sys/param.h>
  159. #include <sys/types.h>
  160. #include <xview/xview.h>
  161. #include <xview/panel.h>
  162. #include <xview/textsw.h>
  163. #include <xview/xv_xrect.h>
  164. #include <gdd.h>
  165. #include "QuoteMaker_ui.h"
  166. #include <sys/stat.h>
  167. #include <xview/font.h>
  168. #include <xview/notice.h>
  169. #include <xview/notify.h>
  170. #include <xview/server.h>          
  171. #include <xview/seln.h>            
  172. #include "Sender.h"
  173. #include "Receiver.h"
  174. #include "quoteMakerDefs.h"
  175.  
  176.  
  177.  
  178. Xv_font *listFont;                            /*  Font used in the main panel and the quoted...   */
  179.                                     /*  text window specs' panel.                       */
  180. Xv_font *displayFont;                            /*  Font used in the Quoted Text Window.            */
  181. Xv_font *annotateFont;
  182.  
  183. int     currentFontFamily;
  184. int    currentFontStyle;
  185. int    currentFontSize;
  186.  
  187. char    *FontFamily[] = {"Default",
  188.             "Default_Fixedwidth",
  189.             "Lucida",
  190.             "Lucida_Fixedwidth",
  191.             "Roman",
  192.             "Serif",
  193.             "Cour"
  194.             };
  195.  
  196. char    *FontStyle[]  = {"Default",
  197.             "Normal",
  198.             "Bold",
  199.             "Italic",
  200.             "Bold_Italic"
  201.             };
  202.  
  203.  
  204. char  *
  205.   UpperCase(s)
  206. char *s;
  207. {
  208.   int  i;
  209.   static int  offset = 'A' - 'a';
  210.   static char result[30];
  211.   
  212.   for(i = 0; i<strlen(s); i++)
  213.   {
  214.     if (s[i] >= 'a' && s[i] <= 'z')
  215.       result[i] = s[i] + offset;
  216.   }
  217.   result[i] = 0;
  218.   return(result);
  219. }
  220.  
  221.  
  222. /*
  223.  *  This function gives the macro (which is in fact a pointer
  224.  *  to a string) corresponding to the item number in the
  225.  *  font family scrolled list.
  226.  */
  227. char *
  228.   GetFontFamilyFromItemNum(inum)
  229. int  inum;
  230. {
  231.   static char familyName[40];
  232.  
  233.   switch(inum) 
  234.   {
  235.    case 0:
  236.     return(strcpy(familyName, FONT_FAMILY_DEFAULT));
  237.    case 1:
  238.     return(strcpy(familyName, FONT_FAMILY_DEFAULT_FIXEDWIDTH));
  239.    case 2:
  240.     return(strcpy(familyName, FONT_FAMILY_LUCIDA));
  241.    case 3:
  242.     return(strcpy(familyName, FONT_FAMILY_LUCIDA_FIXEDWIDTH));
  243.    case 4:
  244.     return(strcpy(familyName, FONT_FAMILY_ROMAN));
  245.    case 5:
  246.     return(strcpy(familyName, FONT_FAMILY_SERIF));
  247.    case 6:
  248.     return(strcpy(familyName, FONT_FAMILY_COUR));
  249.    default:
  250.     fprintf(stderr, "Unknown Font Family Scrolled List option.\n");
  251.     exit(0);
  252.   }
  253. }
  254.  
  255.  
  256. /*
  257.  *  This function gives the macro (which is in fact a pointer
  258.  *  to a string) corresponding to the item number in the
  259.  *  font style scrolled list.
  260.  */
  261. char *
  262.   GetFontStyleFromItemNum(inum)
  263. int  inum;
  264. {
  265.   static char   styleName[40];
  266.  
  267.   switch(inum)
  268.   {
  269.    case 0:
  270.     return(strcpy(styleName, FONT_STYLE_DEFAULT));
  271.    case 1:
  272.     return(strcpy(styleName, FONT_STYLE_NORMAL));
  273.    case 2:
  274.     return(strcpy(styleName, FONT_STYLE_BOLD));
  275.    case 3:
  276.     return(strcpy(styleName, FONT_STYLE_ITALIC));
  277.    case 4:
  278.     return(strcpy(styleName, FONT_STYLE_BOLD_ITALIC));
  279.    default:
  280.     fprintf(stderr, "Unknown Font Style Scrolled List option.\n");
  281.     exit(0);
  282.   }
  283. }
  284.  
  285.  
  286. /*
  287.  *  This function initializes the Font Family Scrolled List
  288.  *  and the Font Style Scrolled List.
  289.  */
  290. void
  291.   InitFontPanel()
  292. {
  293.   int   i;
  294.  
  295.   for(i=0; i< MAX_NUM_OF_FONT_FAMILIES ; i++)    
  296.   {
  297.     xv_set(QuoteMaker_QuoteWindowSpecificationsPopup->FontFamilyList,
  298.        PANEL_LIST_INSERT, i,
  299.        PANEL_LIST_STRING, i, FontFamily[i],
  300.        PANEL_LIST_FONT, i, listFont,
  301.        NULL);
  302.   }
  303.  
  304.   for(i=0; i< MAX_NUM_OF_FONT_STYLES ; i++)
  305.   {
  306.     xv_set(QuoteMaker_QuoteWindowSpecificationsPopup->FontStyleList,
  307.        PANEL_LIST_INSERT, i,
  308.        PANEL_LIST_STRING, i, FontStyle[i],
  309.        PANEL_LIST_FONT, i, listFont,
  310.        NULL);
  311.   }
  312. }
  313.   
  314.  
  315. void
  316.   SetFontPanel(familyNum, styleNum, size)
  317. {
  318.   if (currentFontFamily != NONE_SELECTED)
  319.   {
  320.     xv_set(QuoteMaker_QuoteWindowSpecificationsPopup->FontFamilyList,
  321.        PANEL_LIST_SELECT, currentFontFamily, FALSE, NULL);
  322.   } 
  323.  
  324.   xv_set(QuoteMaker_QuoteWindowSpecificationsPopup->FontFamilyList,
  325.      PANEL_LIST_SELECT, familyNum, TRUE, NULL);
  326.   currentFontFamily = familyNum;
  327.   
  328.   if (currentFontStyle != NONE_SELECTED)
  329.   {
  330.     xv_set(QuoteMaker_QuoteWindowSpecificationsPopup->FontStyleList,
  331.        PANEL_LIST_SELECT, currentFontStyle, FALSE, NULL);
  332.   }
  333.  
  334.   xv_set(QuoteMaker_QuoteWindowSpecificationsPopup->FontStyleList,
  335.      PANEL_LIST_SELECT, styleNum, TRUE, NULL);
  336.   currentFontStyle = styleNum;
  337.   
  338.   xv_set(QuoteMaker_QuoteWindowSpecificationsPopup->FontSizeTextField,
  339.      PANEL_VALUE, size, NULL);
  340.   currentFontSize = size;
  341. }
  342.  
  343.  
  344. void SetQuotedTextWindowLocation(int x, int y)
  345. {
  346.   static Rect  tempRect;
  347.   
  348.   frame_get_rect(QuoteMaker_quotedTextBaseWindow->quotedTextBaseWindow,
  349.          &tempRect);
  350.   tempRect.r_top = y + FRAME_Y_OFFSET;                    /*  Some mysterious offsets need to work around...  */
  351.   tempRect.r_left = x + FRAME_X_OFFSET;                    /*  ...the current location. */
  352.   
  353.   frame_set_rect(QuoteMaker_quotedTextBaseWindow->quotedTextBaseWindow,
  354.          &tempRect);
  355. }  
  356.  
  357.  
  358. void
  359.   SetQuotedTextWindowSize(width, height)
  360. int  width, height;
  361. {
  362.   static Rect  tempRect;
  363.  
  364.   frame_get_rect(QuoteMaker_quotedTextBaseWindow->quotedTextBaseWindow,
  365.          &tempRect);
  366.   tempRect.r_width = width;
  367.   tempRect.r_height = height;
  368.  
  369.   frame_set_rect(QuoteMaker_quotedTextBaseWindow->quotedTextBaseWindow,
  370.          &tempRect);
  371. }                                    /* end function SetQuotedTextWindowSize */
  372.  
  373.   
  374. void
  375.   SetQuotedTextWindowFont(family, style, size)
  376. int family, style, size;
  377. {
  378.   displayFont = (Xv_font *) xv_find(QuoteMaker_quotedTextBaseWindow->quotedTextBaseWindow,
  379.                     FONT,
  380.                     FONT_FAMILY, GetFontFamilyFromItemNum(family),
  381.                     FONT_STYLE, GetFontStyleFromItemNum(style),
  382.                     FONT_SIZE, size,
  383.                     NULL);
  384.  
  385.   if (displayFont)
  386.   {
  387.     xv_set(QuoteMaker_quotedTextBaseWindow->quotedTextPane,
  388.        XV_FONT, displayFont,
  389.        NULL);
  390.   }
  391.   else
  392.   {
  393.     AlertByNoticePrompt(QuoteMaker_baseWindow->baseWindow,
  394.             "Sorry, this combination of font family and style is not currently available.");
  395.   }
  396.   
  397. }
  398.  
  399. /*
  400.  *  This function preload fonts onto the Quoted Text Window.
  401.  */
  402. void
  403.   PreloadFontsOntoQTW()
  404. {
  405.   int   counter;
  406.   
  407.   ClearQuotedTextWindow();
  408.   for(counter = 0; counter < editList.numItems ; counter++)        
  409.   {                                    
  410.     displayFont = (Xv_font *) xv_find(QuoteMaker_quotedTextBaseWindow->quotedTextBaseWindow,
  411.                       FONT,
  412.                       FONT_FAMILY, GetFontFamilyFromItemNum(editList.fontFamily[counter]),
  413.                       FONT_STYLE, GetFontStyleFromItemNum(editList.fontStyle[counter]),
  414.                       FONT_SIZE, editList.fontSize[counter],
  415.                       NULL);
  416.     if (displayFont)
  417.     {
  418.       xv_set(QuoteMaker_quotedTextBaseWindow->quotedTextPane,
  419.          XV_FONT, displayFont,
  420.          NULL);
  421.     }
  422.   }
  423. }                                    /* end function PreloadFontsOntoQTW */
  424.